package com.lazyframework.generator.core;

import java.util.HashMap;
import java.util.Map;

/**
 * 数据库数据类型和Java数据类型映射表
 * <p>
 * Create by lazy in 2020/07/26
 */
public class DBTypeMappings {

    protected static Map<String, String> TYPE_MAPPING;

    public static String getJavaType(String type) {
        return TYPE_MAPPING.get(type.toUpperCase());
    }

    static {
        TYPE_MAPPING = new HashMap<>();
        TYPE_MAPPING.put("CHAR", "String");
        TYPE_MAPPING.put("VARCHAR", "String");
        TYPE_MAPPING.put("LONGVARCHAR", "String");
        TYPE_MAPPING.put("NUMERIC", "java.math.BigDecimal");
        TYPE_MAPPING.put("DECIMAL", "java.math.BigDecimal");
        TYPE_MAPPING.put("BIT", "Boolean");
        TYPE_MAPPING.put("BOOLEAN", "Boolean");
        TYPE_MAPPING.put("TINYINT", "Integer");
        TYPE_MAPPING.put("SMALLINT", "Integer");
        TYPE_MAPPING.put("INT", "Integer");
        TYPE_MAPPING.put("BIGINT", "Long");

        TYPE_MAPPING.put("FLOAT", "Double");
        TYPE_MAPPING.put("DOUBLE", "Double");

        TYPE_MAPPING.put("BINARY", "Byte[]");
        TYPE_MAPPING.put("VARBINARY", "Byte[]");
        TYPE_MAPPING.put("LONGVARBINARY", "Byte[]");

        TYPE_MAPPING.put("DATE", "java.time.LocalDate");
        TYPE_MAPPING.put("TIME", "java.time.LocalTime");
        TYPE_MAPPING.put("DATETIME", "java.time.LocalDateTime");
        TYPE_MAPPING.put("TIMESTAMP", "java.time.LocalDateTime");

        TYPE_MAPPING.put("TEXT", "String");
        TYPE_MAPPING.put("LONGTEXT", "String");

        TYPE_MAPPING.put("CLOB", "Clob");
        TYPE_MAPPING.put("BLOB", "Blob");
        TYPE_MAPPING.put("DATALINK", "java.util.Date");
    }
}
